﻿@{
    ViewData["Title"] = "用户";
}
@section style {
    <link rel="stylesheet" href="~/admin/css/other/profile.css" />
}
<div class="layui-row layui-col-space10">
    <div class="layui-col-md3">
        <div class="layui-card">
            <div class="layui-card-body" style="padding: 25px;">
                <div class="text-center layui-text">
                    <div class="user-info" id="userInfoHead">
                        <img src="../../admin/images/avatar.jpg" id="userAvatar" width="115px" height="115px"
                             alt="">
                    </div>
                    <h2 class="user-name">{{userinfo.account}}</h2>
                    <p class="user-home">{{userinfo.realName}}</p>
                </div>
            </div>
            <div class="user-desc">
                <span>{{userinfo.orgName}}</span>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-header">密码修改</div>
            <div class="layui-card-body">
                <form class="layui-form">
                    <div class="layui-form-item">
                        <label class="layui-form-label">旧密码</label>
                        <div class="layui-input-block">                          
                            <input type="password" name="passwordOld" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">新密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="passwordNew" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-block">
                            <input type="password" name="passwordNew1" lay-verify="required" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="passwd">确定修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <div class="layui-col-md9">
        <div class="layui-card">
            <div class="layui-card-header">
                登录日志
            </div>
            <div class="layui-card-body">
                <div class="layui-row layui-col-space10" style="margin: 15px;" v-for="item in logs">
                    <div class="layui-col-md1">
                        <img src="../../admin/images/blog.jpg" style="width: 100%;height: 100%;border-radius: 5px;" />
                    </div>
                    <div class="layui-col-md11" style="height: 80px;">
                        <div class="blog-title">{{item.displayTitle}} -- {{item.createTime}} </div>
                        <div class="blog-content">
                            IP: {{item.remoteIp}} ； 操作系统: {{item.os}} ；浏览器: {{item.browser}}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts {
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                logs: [],
                userinfo: {},
            }
        });
        layui.use(['toast', 'http'], function () {
            var table = layui.table,
                $ = layui.$,
                form = layui.form,
                http = layui.http,
                toast = layui.toast;
            //
            http.get('/api/sysAuth/userInfo').then((res) => {
                vm.userinfo = res.result
            });
            http.post('/api/sysLogVis/page', { pagesize: 6 }).then((res) => {
                vm.logs = res.result.items
            });
            form.on('submit(passwd)', function (data) {
                //
                if (data.field.passwordNew != data.field.passwordNew1) {
                    toast.error({
                        message: '两次密码不不一致！',
                    });
                    return false;
                }
                //
                http.post('/api/sysUser/changePwd', data.field).then((res) => {
                    if (res.code == 200) {
                        toast.success({
                            message: '修改成功，请重新登录！',
                        });
                    }
                    else {
                        toast.error({
                            message: res.message,
                        });
                    }                   
                });
                return false;
            })
        })
    </script>
}
